<?php
/**
 * Data Model
 *
 * @property Data $ParentData
 * @property Data $ChildData
 */
class WxUser extends WechatAppModel {

/**
 * Use table
 *
 * @var mixed False or table name
 */
	public $useTable = false;
	
	public function getOauthLink($url){
	    $redirect = Router::url($url,true);
	    $link = "https://open.weixin.qq.com/connect/oauth2/authorize".
	    "?appid=".Configure::read("Wechat.appID").
	    "&redirect_uri=".urlencode($redirect).
	    "&response_type=code".
	    "&scope=snsapi_userinfo". //snsapi_userinfo详细数据 snsapi_base基础数据
	    "&state=redirectauth#wechat_redirect";
	    
	    return $link;
	}
	
	public function access_token($code){
	    $link = "https://api.weixin.qq.com/sns/oauth2/access_token".
	    "?appid=".Configure::read("Wechat.appID").
	    "&secret=".Configure::read("Wechat.appsecret").
	    "&code=".$code.
	    "&grant_type=authorization_code";
	    return $this->request($link);
	}
	
	public function userinfo($access_token,$openid){
	    $link = "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid&lang=zh_CN";
	    return $this->request($link);
	}
	
}
